<?php
require_once '../dao/NotificationDao.php';
require_once '../entity/Notification.php';

$action = "";
if (isset($_GET['action'])) {
	$action = $_GET['action'];
}

switch ($action) {
	case 'getNotifications' :
		getNotifications();
		break;
	case 'updateNotificationView' :
		updateNotificationView();
		break;
	case 'getCountNotificationToView' :
		getCountNotificationToView();
		break;
	default :
		$jsonResult['result'] = "ERROR";
		$jsonResult['message'] = "no action found";
		print json_encode($jsonResult);
		break;
}


/*
 * Permit to retrieve notifications of a masker
 */
function getNotifications() {
	$notificationDao = new NotificationDao();
	$jsonResult = array();

	// check if id masker is isset
	if (!isset($_POST['id_masker'])) {
		$jsonResult['result'] = "ERROR";
		$jsonResult['message'] = "no id_masker found";
	} else {
		$idMasker = $_POST['id_masker'];
		$value = $notificationDao -> getNotifications($idMasker);
		$jsonResult['value'] = ($value);
	}
	print json_encode($jsonResult);
}
/*
 * Permit to sign notification to view
 */
function updateNotificationView() {
	$notificationDao = new NotificationDao();
	$jsonResult = array();

	// check if id masker is isset
	if (!isset($_POST['id_masker'])) {
		$jsonResult['result'] = "ERROR";
		$jsonResult['message'] = "no id_masker found";
	} else {
		$idMasker = $_POST['id_masker'];

		$result = $notificationDao -> updateNotificationView($idMasker);
		$jsonResult['result'] = ($result);
	}

	print json_encode($jsonResult);
}

/*
 * Permit to get the number of the new notification of a masker
 */
function getCountNotificationToView() {
	$notificationDao = new NotificationDao();
	$jsonResult = array();

	// check if id masker is isset
	if (!isset($_POST['id_masker'])) {
		$jsonResult['result'] = "ERROR";
		$jsonResult['message'] = "no id_masker found";
	} else {
		$idMasker = $_POST['id_masker'];

		$result = $notificationDao -> getCountNotificationToView($idMasker);
		$jsonResult['value'] = ($result["COUNT"]);
	}

	print json_encode($jsonResult);
}
?>